//
//  MyMovieViewController.m
//  UI_豆瓣
//
//  Created by WangZe on 15/10/13.
//  Copyright © 2015年 王泽龙. All rights reserved.
//

#import "MyMovieViewController.h"
#import "MovieList.h"
#import "MovieListCell.h"
#import "UIImageView+WebCache.h"
#import "MovieDetailsViewController.h"

@interface MyMovieViewController ()<UITableViewDataSource, UITableViewDelegate>
@property(nonatomic, retain)UITableView *tableView;
@property(nonatomic, retain)NSMutableArray *arr;
@end

@implementation MyMovieViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    [_tableView release];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:87 / 255.0 green:137 / 255.0 blue:157 / 255.0 alpha:1];
    self.title = @"我的电影";
    NSString *sandBoxPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString *docPath = [sandBoxPath stringByAppendingPathComponent:@"Movie/movie.plist"];
    self.arr = [NSMutableArray array];
    self.arr = [NSKeyedUnarchiver unarchiveObjectWithFile:docPath];
    
    self.tableView.rowHeight = 200;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MovieDetailsViewController *mdVC = [[MovieDetailsViewController alloc] init];
    [self.navigationController pushViewController:mdVC animated:YES];
    MovieList *mv = self.arr[indexPath.row];
    mdVC.movieID = mv.movieId;
    mdVC.tempMovie = mv;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuse = @"reuse";
    MovieListCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (!cell) {
        cell = [[MovieListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse];
    }
    MovieList *mv = self.arr[indexPath.row];
    cell.mvName.text = mv.movieName;
    [cell.mvimageView sd_setImageWithURL:[NSURL URLWithString:mv.pic_url]];
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
